package com.egdigital.allzic.ui.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;
import com.egdigital.allzic.R;
import com.egdigital.allzic.data.object.Country;

public class AdapterCountry extends BaseAdapter {

	// log
	private static final String	TAG				= AdapterCategory.class.getSimpleName();
	// data
	private LayoutInflater		mInflater;
	private List<Country>		mList;
	private boolean				mLastColorWhite	= true;

	private static class CellHolderCategory {

		TextView		mTitle;
		RelativeLayout	mLayout;
	}

	public AdapterCountry(Context context, List<Country> list) {
		mList = list;
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public int getCount() {
		return mList.size();
	}

	public Country getItem(int position) {
		return mList.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	@Override
	public int getViewTypeCount() {
		return 1;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		CellHolderCategory holder = null;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.cell_list_category, parent, false);
			holder = new CellHolderCategory();
			holder.mTitle = (TextView) convertView.findViewById(R.id.adapter_category_title);
			holder.mLayout = (RelativeLayout) convertView.findViewById(R.id.adapter_category_layout);
			convertView.setTag(holder);
			YoYo.with(Techniques.FadeIn).duration(500).playOn(convertView);
		} else {
			holder = (CellHolderCategory) convertView.getTag();
		}
		// color
		if (mLastColorWhite == true) {
			holder.mLayout.setBackgroundResource(R.drawable.selector_list_blue);
			mLastColorWhite = false;
		} else {
			holder.mLayout.setBackgroundResource(R.drawable.selector_list_simple);
			mLastColorWhite = true;
		}
		// set
		holder.mTitle.setText(((Country) mList.get(position)).getTitle());
		return convertView;
	}

	public void setRows(List<Country> rows) {
		this.mList = rows;
	}
}
